package cn.schoolwow.workflow.module.task.action.flow.complete.transaction;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.workflow.domain.deploy.DeployNodeType;
import cn.schoolwow.workflow.entity.WorkFlowNode;
import cn.schoolwow.workflow.module.task.action.flow.common.SetNodeAssignerFinishedOptionCommonFlow;
import cn.schoolwow.workflow.module.task.action.flow.complete.nodeType.gateway.HandleExclusiveGatewayFlow;
import cn.schoolwow.workflow.module.task.action.flow.complete.nodeType.gateway.HandleInclusiveGatewayFlow;
import cn.schoolwow.workflow.module.task.action.flow.complete.nodeType.gateway.HandleParallelGatewayFlow;
import cn.schoolwow.workflow.module.task.action.flow.complete.nodeType.general.*;

public class InsertWorkFlowTaskFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        WorkFlowNode nextNode = flowContext.checkData("nextNode", WorkFlowNode.class);

        DeployNodeType deployNodeType = DeployNodeType.getDeployNodeType(nextNode.getType());
        switch (deployNodeType) {
            case StartNode: {}break;
            case AuditNode: {flowContext.executeFlowList(new HandleAuditNodeFlow());}break;
            case EndNode: {flowContext.executeFlowList(new HandleEndNodeFlow());}break;
            case PassNode:{flowContext.executeFlowList(new HandlePassNodeFlow());}break;
            case RejectNode:{flowContext.executeFlowList(new HandleRejectNodeFlow());}break;
            case ParallelGateway: {flowContext.executeFlowList(new HandleParallelGatewayFlow());}break;
            case ExclusiveGateway: {flowContext.executeFlowList(new HandleExclusiveGatewayFlow());}break;
            case InclusiveGateway: {flowContext.executeFlowList(new HandleInclusiveGatewayFlow());}break;
            case CarbonCopyNode: {flowContext.executeFlowList(new HandleCarbonCopyNodeFlow());}break;
        }

        flowContext.startFlow(new SetNodeAssignerFinishedOptionCommonFlow())
                .putCurrentCompositeFlowInstanceData(nextNode)
                .execute();
    }

    @Override
    public String name() {
        return "添加工作流实例任务";
    }

}